package com.cy.api;

import com.cy.service.RemoteProviderService;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class RemoteProFallbackFactory implements FallbackFactory<RemoteProviderService> {
    //org.slf4j.Logger门面模式，io是装饰模式
//    private static final Logger log = LoggerFactory.getLogger(RemoteProFallbackFactory.class);
    //org.slf4j.Logger是Java中日志的规范，定义了一组接口
    //这个接口的实现有log4j,logback
    @Override
    public RemoteProviderService create(Throwable throwable) {
    log.error("调用服务提供失败：{}", throwable.getMessage());//{}占位符，右边的变量值交给他
//        return new RemoteProviderService() {
//            @Override
//            public String echoMessage(String msg) {
//                return "忙着呢，没空理你！";
//            }
//        };
        /*简化写法，借助了jdk8中的lambda表达式，当接口中只有一个方法需要实现时，可以使用简化写法
        return (String msg) -> {
                return "忙着呢，没空理你！";
        };*/
        return (msg)->"服务忙，稍后再访问！";
    }
}
